﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Linq.Expressions;

namespace LinqToSQL.Manning
{
    class Expressions
    {

        #region Constructor
        private static Expressions _Instance = null;
        private Expressions()
        {
        }
        static readonly private object padLock = new object();
        public static Expressions Instance
        {
            get
            {
                if (_Instance == null)
                    lock (padLock)
                    {
                        if (_Instance == null)
                            _Instance = new Expressions();
                    }
                return _Instance;
            }
        }
        #endregion

        public void simpleExample()
        {
            Expression firstArg = Expression.Constant(2);
            Expression secondArg = Expression.Constant(3);
            Expression add = Expression.Add(firstArg, secondArg);
            string exprString = add.ToString();

            Func<int> compiled = Expression.Lambda<Func<int>>(add).Compile();
            int result = compiled();

            //creating expression tree with lambda
            Expression<Func<int>> return5 = () => 5;
            Func<int> compiled2 = return5.Compile();
            result = compiled2();
        }

    }
}
